package cn.gok.dor.manager.service.impl;

import cn.gok.dor.manager.controller.dto.StudentQueryDTO;
import cn.gok.dor.manager.controller.vo.StudentListVO;
import cn.gok.dor.manager.entity.Student;
import cn.gok.dor.manager.service.IStudentService;
import cn.gok.dor.manager.dao.StudentDAO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description:
 * @Author: chenfan
 * @date: 2023-09-07 18:20
 */
@Service
public class StudentServiceImpl implements IStudentService {

    @Resource
    private StudentDAO studentDAO;

    @Override
    public StudentListVO getStudents(StudentQueryDTO queryParam) {
        StudentListVO studentListVO = new StudentListVO();

        //在查询结果集之前，调用pageHelper提供的分页方法即可实现分页效果
        PageHelper.startPage(queryParam.getPageNum(), queryParam.getPageSize());
        List<Student> students = studentDAO.findStudents(queryParam);

        //获取分页数据对象
        PageInfo<Student> pageInfo = new PageInfo<>(students);
        studentListVO.setRows(students);
        studentListVO.setTotal(pageInfo.getTotal());
        return studentListVO;
    }
}
